<?php
require_once "includes/transformer/Transformer.php";
require_once "includes/cryptography/RC4CryptHandler.php";
require_once "Net/URL2.php";

class CssTransformer extends Transformer
{
    public function __construct(Net_URL2 &$url)
    {
    	parent::__construct($url);
    }
	
	public function transform(&$content){
		$content = preg_replace_callback(
	        '/(url)[\s\r\t]*[\("\']+(\/?[^\)"\'\s]+)[\)"\']+\/?/i',
	        array(get_class($this), 'callback'),
	        $content
	    );
	}
	
    private function callback($matches) {
    	$matchedUrl = new Net_URL2($matches[2]);
    	if(!$matchedUrl->isAbsolute()){
    		$matchedUrl = $this->url->resolve($matchedUrl);
    	}
    	return $matches[1]."(d.php?u=".RC4CryptHandler::encrypt($matchedUrl->getNormalizedURL()).")";
    }
}
?>